#ifndef _FUNCOES_H
#define _FUNCOES_H

#include <QDialog>
#include <QTcpSocket>
#include <QtGui>
#include <QtNetwork>

#include "db.h" 
#include <iostream>
#include <deque>

class Client;
class MyThread;

enum FUNCOES{
	HAND_SHAKE = 0, 
	GET_WELL_LIST = 1,
	REGISTER_WELL = 2,
	GET_STATE_WELL = 3,
	GET_ALL_DATA_FROM_WELL = 4,
	GET_MASTERS_LIST = 5,
	GET_LETTER_FROM_WELL = 6,
	DELETE_WELL = 7,
	GET_ALARMS_FROM_WELL = 8,
	GET_HISTORIC_FROM_WELL = 9,
	CHANGE_TIMEOUT_WELL = 10
	};

class SocketClient :public QObject{
Q_OBJECT
	public:
		SocketClient();
		~SocketClient();	
		int sendFunction(int idFunction,QStringList Parans);
		QTcpSocket *sck;
		quint16 blockSize;
		int id;		
		db dbConnection;
		std::deque<QStringList> requestsVector;
		

		void addRequest(QStringList);		
		
		//funcoes de tratamento de requests
		QStringList loginRequest(QStringList);		
		QStringList treatWellList();
		QStringList treatRegisterWell(QStringList);
		QStringList treatGetStateWell(QStringList);
		QStringList trestGetLetterFromWellAux(int,int);
		QStringList trestGetAllDataFromWell(QStringList);
		QStringList trestGetLetterFromWell(QStringList);
		QStringList treatMastersList();
		QStringList treatDeleteWell(QStringList);
		QStringList trestGetAllDataFromWell(int, int);
		QStringList treatGetAlarmsFromWellAux(int,int);
		QStringList treatGetAlarmsFromWell(QStringList);
		QStringList treatGetHistoricFromWell(QStringList);
		QStringList treaChangeTimeout(QStringList);
		QString alarmToDB(int wellId, int idSimulador);
		
		std::vector<MyThread *> tVector;
	public slots:
		void processAux(QStringList);
		void process();
	private:
		QStringList trestGetAllDataFromWellAux(uint8_t wellId,int idSimulador,QStringList,uint16_t,int);
};

class MyThread : public QThread {

	public:
	SocketClient *thz;
		virtual void run(){
			thz->process();
		}
};



#endif
